package en.edu.zxj.mq.demo;

import en.edu.zxj.mq.mqclient.Channel;
import en.edu.zxj.mq.mqclient.Connection;
import en.edu.zxj.mq.mqclient.ConnectionFactory;
import en.edu.zxj.mq.mqserver.core.ExchangeType;

import java.io.IOException;
import java.util.concurrent.BlockingQueue;

/**
 * Created with IntelliJ IDEA.
 * Description：简单的使用使用一下 mq 服务器而编写的 Demo 程序
 * 客户端的生产者
 *
 * @author: zxj
 * @date: 2024-03-07
 * @time: 14:52:54
 */
public class DemoProducer {
    public static void main(String[] args) throws IOException, InterruptedException {
        System.out.println("启动生产者");
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(9090);

        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();

        // 创建交换机和队列
        channel.exchangeDeclare("testExchangeName", ExchangeType.DIRECT, true, false, null);
        channel.queueDeclare("testQueueName", true, false, false, null);


        // 创建一个消息并发送
        byte[] body = "Hello RabbitMQ".getBytes();
        boolean ok = channel.basicPublish("testExchangeName", "testQueueName", null, body);
        System.out.println("消息投递成功! ok = " + ok);

        Thread.sleep(500);

        channel.close();
        connection.close();


    }
}
